package com.example.collegevice.controller;

import com.example.collegevice.service.CollegeService;
import com.example.common.Result;

import com.example.pojo.College;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学院信息前端请求的接口入口
 */
@RestController
@RequestMapping("/college")
public class CollegeController {

    @Resource
    private CollegeService collegeService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody College college) {
        collegeService.add(college);
        return Result.success();
    }

    /**
     * 更新
     */
    @PutMapping("/update")
    public Result update(@RequestBody College college) {
        collegeService.updateById(college);
        return Result.success();
    }
    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }
    /**
     * 根据id删除
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        collegeService.deleteById(id);
        return Result.success();
    }

    /**
     * 自己添加的微服务根据id查询
     */
    @GetMapping("/selectById/{id}")
    public College selectById(@PathVariable Integer id){
        return collegeService.selectById(id);
    }


    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(College college,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize) {
        PageInfo<College> pageInfo = collegeService.selectPage(college, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll() {
        List<College> list = collegeService.selectAll();
        return Result.success(list);
    }
}
